using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameStateManagement.View
{
    class Camera
    {
        private readonly SpriteBatch _spriteBatch;
        private Matrix _cameraMatrix;

        public Camera(SpriteBatch spriteBatch)
        {
            _spriteBatch = spriteBatch;
            _cameraMatrix = Matrix.Identity;
        }

        public void Move(Vector2 delta)
        {
            _cameraMatrix *= Matrix.CreateTranslation(new Vector3(delta, 0));
        }

        public void Zoom(Vector3 zoomCenter, float scale)
        {
            _cameraMatrix *= Matrix.CreateScale(scale) * Matrix.CreateTranslation(zoomCenter);
        }

        public void BeginFrame()
        {
            _spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, _cameraMatrix);    
        }

        public void EndFrame()
        {
            _spriteBatch.End();
        }

        public void ResetCamera()
        {
            _cameraMatrix = Matrix.Identity;
        }
    }
}
